package object2D;

import byggeTegner.DrawPanel;
import context.*;
import model2D.Model2D;
import object3D.Kanal;

import geometry2D.Projection2D;

import java.awt.Color;
import java.awt.Graphics2D;

import org.json.JSONException;
import org.json.JSONObject;

import util.FillStyle;
import util.StrokeStyle;
import util.Util;

//***************************************************************************
//*** CLASS: KanalProjection
//***************************************************************************
public class KanalProjection extends BlockProjection implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final String TAG="object2D.KanalProjection";
  static final String TYPE="Kanal";

  protected Kanal getKanal() { return((Kanal)block); }
		
	  // *************************************************************************
	  // *** CONSTRUCTOR: KanalProjection
	  // *************************************************************************
	  public KanalProjection(Model2D objectModel,Kanal kanal,int type,int direction,Color color,float opacity)
	  throws JSONException
	  { super(objectModel,kanal,type,direction,color,opacity); }
	  
	  public KanalProjection(Model2D objectModel,JSONObject jsonObject) throws JSONException
	  { super(objectModel,jsonObject);
	    if(DEBUG) Log.d(TAG,"decodeSVG: jsonObject="+jsonObject);
	    this.fill=new FillStyle(jsonObject);
	    this.stroke=new StrokeStyle(jsonObject);
//	    boolean closed=jsonObject.optBoolean("closed",false);
//	    JSONArray d=jsonObject.getJSONArray("d");
//	    //if(DEBUG) Log.d(TAG,"PathObject.decodeSVG: name="+name+", d="+d);
//	    clearPointSet();
//	    for(int i=0;i<d.length();i++)
//	    { JSONArray p=d.getJSONArray(i);
//	      add(new MetricPoint2D(p));
//	    }
//	    setClosedPath(closed);
	  }

	  public JSONObject toJSONObject() throws JSONException
	  { JSONObject jsonObject=new JSONObject();
	    jsonObject.put("type",TYPE);
	    jsonObject.put("id",getIdent());
//	    jsonObject.put("closed",getClosedPath());  
//	    jsonObject.put("d",getD());
	    jsonObject.put("fill",fill.encode());
	    jsonObject.put("stroke",stroke.encode());
		return(jsonObject);
	  }


	  // *************************************************************************
	  // *** METHOD: paint
	  // *************************************************************************
	  public void paint(Graphics2D g,DrawPanel drawPanel)
	  { Projection2D r=block.toProjection2D(direction);
	    Util.fill(g,r,color,opacity);
//	    Util.draw(g,r,opacity);
	    if(direction==ABOVE) paintExtraProjection(g,drawPanel);
	  }



}
